package com.theeviljames.coursework.server;

import java.io.DataOutputStream;
import java.util.Hashtable;
import java.util.TimerTask;

public class RadioServerTimerTask extends TimerTask {

	private DataOutputStream out;
	private Hashtable<Integer, String> messages;
	private int counter;
	
	public RadioServerTimerTask(DataOutputStream out) {
		this.out = out;
		init();
		counter = 0;
		
	}

	@Override
	public void run() {
		try{
			out.writeBytes(getNextSample());
		}
		catch(Exception e){
			
		}
	}
	
	private String getNextSample(){
		return ((counter%10)+1) + "#" + messages.get(counter++%10)+"\n";
	}
	
	private void init(){
		messages = new Hashtable<Integer, String>();
		messages.put(0,"One");
		messages.put(1,"Two Two");
		messages.put(2,"Three Three Three");
		messages.put(3,"Four Four Four Four");
		messages.put(4,"Five Five Five Five Five");
		messages.put(5,"Six Six Six Six Six Six");
		messages.put(6,"Seven Seven Seven Seven Seven Seven Seven");
		messages.put(7,"Eight Eight Eight Eight Eight Eight Eight Eight");
		messages.put(8,"Nine Nine Nine Nine Nine Nine Nine Nine Nine");
		messages.put(9,"Ten Ten Ten Ten Ten Ten Ten Ten Ten Ten");
	}
}
